﻿/*-----------------------------------------------------------------------
 * <copyright file="SetAccountRolesCtrl.xaml.cs" company="O-RID">
 *     Copyright (c)2010 O-RID Co.,Ltd.
 * </copyright>
 * <author>Zhang jun </author>
 * <summary>
 *          权限设置  
 * 
 *  开始日期: 2010-9-3 11:54:11
 *  作成日:   2010-9-8
 * </summary>
 *----------------------------------------------------------------------- 
 */
namespace Orid.Management.Statistics.OperatorUnitMangement.CompetenceSetPaeg.SetAccountRoles
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using Orid.Management.Statistics.OperatorUnitMangement.Common.FunctionList;
    using Orid.Management.Statistics.OperatorUnitMangement.WCFServers.WCFAccountsRef;
    using childWindow = Orid.Management.Statistics.OperatorUnitMangement.Common.Window;

    public partial class SetAccountRolesCtrl : UserControl
    {
        #region 全局变量
        /// <summary>
        /// 用于TAB标签的选择
        /// </summary>
        public enum TabelType 
        {
            TreeTabel,
            RolesTabel,
        }

        /// <summary>
        /// 当前页面的名字（日志用）
        /// </summary>
        private const string pageName = " - 权限设置页面 - ";

        /// <summary>
        /// 树形结构信息
        /// 将服务端树形结构存信息储在客户端
        /// </summary>
        private List<ClientTreeInfor> clientTreeInforList = null;

        /// <summary>
        /// 获取树形结构服务
        /// WCFAccountsClient
        /// </summary>
        private WCFAccountsClient clientTreeView = null;

        /// <summary>
        /// 消息子窗体 errorMessbox
        /// </summary>
        private childWindow.MessageBox errorMessbox = null;

        /// <summary>
        /// 日志服务定义
        /// wcfLogClient
        /// </summary>
        private WCFLog4Ref.WCFLog4Client wcfLogClient = null;

        /// <summary>
        /// 记录 客户端的数据，用于 权限树结点 增加/修改/删除
        /// </summary>
        private WCFServers.WCFAccountsRef.TreeViewDataList paramTreeClass = null;

        /// <summary>
        /// 记录 客户端的数据，用于 身份管理 增加/修改/删除
        /// </summary>
        private WCFServers.WCFAccountsRef.RolesCombboxDataList paramRolesClass = null;

        /// <summary>
        /// 增删改的 服务 引用
        /// </summary>
        private WCFServers.WCFAccountsRef.WCFAccountsClient accountClinet = null;

        /// <summary>
        /// 
        /// </summary>
        TreeView TreeOfList = null;

        #endregion 全局变量

        /// <summary>
        /// 动态树
        /// </summary>
        public SetAccountRolesCtrl()
        {
            InitializeComponent();
            this.InitField();

            // 引用主题
            ((App)Application.Current).SetTheme((Grid)LayoutRoot);

            // 显示 树形结构 的服务委托
            this.clientTreeView.TreeViewListCompleted += new EventHandler<TreeViewListCompletedEventArgs>(this.ClientTreeView_TreeViewListCompleted);

            #region 权限树设置

            //确定按钮
            this.btnOK.Click += new RoutedEventHandler(btnOK_Click);
            
            //下拉框选择事件
            this.cbSelectTpye.SelectionChanged += new SelectionChangedEventHandler(cbSelectTpye_SelectionChanged);
            
            //树结点 增删改的服务委托
            accountClinet.TreeViewNodeCompleted += new EventHandler<TreeViewNodeCompletedEventArgs>(AccountClinet_TreeViewNodeCompleted);
            
            //取消
            this.btnTreeCancel.Click += new RoutedEventHandler(btnTreeCancel_Click);

            #endregion #region 权限树设置

            #region  身份权限设置

            //下拉框选择事件
            this.cbRolesSelectTpye.SelectionChanged += new SelectionChangedEventHandler(cbRolesSelectTpye_SelectionChanged);
            
            //显示所有的用户身份 委托
            accountClinet.AllRolesListCompleted += new EventHandler<AllRolesListCompletedEventArgs>(AccountClinet_AllRolesListCompleted);
            
            // DATAGRID的记录单击事件
            this.dgAllRolesList.SelectionChanged += new SelectionChangedEventHandler(dgAllRolesList_SelectionChanged);
            
            //确定按钮
            this.btnRolesOK.Click += new RoutedEventHandler(btnRolesOK_Click);
            
            //身份权限设置 增删改的服务委托
            this.accountClinet.EditRolesListCompleted += new EventHandler<EditRolesListCompletedEventArgs>(accountClinet_EditRolesListCompleted);
            
            //取消
            this.btnRolesCancel.Click += new RoutedEventHandler(btnRolesCancel_Click);

            #endregion  身份权限设置

            //页面载入
            this.Loaded += new RoutedEventHandler(SetAccountRolesCtrl_Loaded);

            // 设置背景色
            LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(255, 243, 244, 245));

        }

        /// <summary>
        /// 变量初始化
        /// </summary>
        private void InitField()
        {
            this.clientTreeInforList = new List<ClientTreeInfor>();
            this.clientTreeView = new WCFAccountsClient();
            this.errorMessbox = new childWindow.MessageBox();
            this.wcfLogClient = new WCFLog4Ref.WCFLog4Client();
            this.accountClinet = new WCFServers.WCFAccountsRef.WCFAccountsClient();
        }

        /// <summary>
        /// 页面载入
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void SetAccountRolesCtrl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // 根据当前用户权限，来显示树形结构
                IsEnableTextBox(TabelType.TreeTabel,false);
                IsEnableTextBox(TabelType.RolesTabel, false);

                CreateNewTreeView();

                //判断当前用户是否有操作此页面的权限
                if (ClientUserInfor.RoleID.Equals("1"))
                {
                    if (!String.IsNullOrEmpty(ClientUserInfor.Condition))
                    {
                        this.clientTreeView.TreeViewListAsync(string.Empty,false);
                        this.accountClinet.AllRolesListAsync();
                    }
                }
                else
                {
                    throw new Exception("当前用户没有此页面的操作权限！");
                }

                this.dpTree.Children.Clear();
                this.dpTree.Children.Add(TreeOfList);
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName +"Loaded方法 " + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #region 权限树设置
        /// <summary>
        /// 下拉框选择事件
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void cbSelectTpye_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.paramTreeClass = null;
            this.paramTreeClass = new WCFServers.WCFAccountsRef.TreeViewDataList();
            switch (this.cbSelectTpye.SelectedIndex) 
            {
                case 0:
                    this.IsEnableTextBox(TabelType.TreeTabel, false);
                    break;
                case 1:
                    //添加一个新节点
                    
                    //清空当前文本框
                    this.tbNodeID.Text = string.Empty;
                    this.tbNodeIDName.Text = string.Empty;
                    this.tbParentNodeID.Text = string.Empty;
                    this.tbURL.Text = string.Empty;

                    this.IsEnableTextBox(TabelType.TreeTabel, true);

                    break;
                case 2:
                    //编辑当前节点
                    this.IsEnableTextBox(TabelType.TreeTabel, true);

                    //记录要编辑的NodeID号
                    this.paramTreeClass.OldNodeID = this.tbNodeID.Text.Trim();

                    break;
                case 3:
                    //删除当前节点

                    break;
                default:
                    //不可操作的选择
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.IsEnableTextBox(TabelType.TreeTabel, false);
                switch (this.cbSelectTpye.SelectedIndex)
                {
                    case 0:
                        //刷新
                        CreateNewTreeView();

                        this.clientTreeView.TreeViewListAsync(string.Empty, false);

                        this.dpTree.Children.Clear();
                        this.dpTree.Children.Add(TreeOfList);

                        break;
                    case 1:
                        //添加一个新节点
                        //判断输入的TextBox是否有空值 
                        IsEmptyTextBox(this.setCheckValueStackPanel);

                        this.paramTreeClass.NodeID = this.tbNodeID.Text.Trim();
                        this.paramTreeClass.NodeName = this.tbNodeIDName.Text.Trim();
                        this.paramTreeClass.NodeParendID = this.tbParentNodeID.Text.Trim();
                        this.paramTreeClass.TagUri = this.tbURL.Text.Trim();

                        break;
                    case 2:
                        //编辑当前节点
                        IsEmptyTextBox(this.setCheckValueStackPanel);

                        this.paramTreeClass.NodeID = this.tbNodeID.Text.Trim();
                        this.paramTreeClass.NodeName = this.tbNodeIDName.Text.Trim();
                        this.paramTreeClass.NodeParendID = this.tbParentNodeID.Text.Trim();
                        this.paramTreeClass.TagUri = this.tbURL.Text.Trim();
                        //要编辑的NodeID号已经记录

                        break;
                    case 3:
                        //删除当前节点
                        if (string.IsNullOrEmpty(this.tbNodeID.Text.Trim()))
                        {
                            throw new Exception("选择要删除的内容！");
                        }
                        this.paramTreeClass.NodeID = this.tbNodeID.Text.Trim();
                        break;
                    default:
                        //不可操作的选择
                        this.paramTreeClass = null;
                        break;
                }
                if (this.paramTreeClass == null) 
                {
                    throw new Exception("请选择一个操作!");
                }

                if (this.cbSelectTpye.SelectedIndex != 0)
                {
                    //调用服务
                    this.accountClinet.TreeViewNodeAsync(this.paramTreeClass, (this.cbSelectTpye.SelectedItem as ComboBoxItem).Tag.ToString());
                }
                this.cbSelectTpye.SelectedIndex = -1;

            }
            catch (Exception ex)
            {
                this.cbSelectTpye.SelectedIndex = -1;
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + "确定按钮操作btnOK_Click" + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnTreeCancel_Click(object sender, RoutedEventArgs e)
        {
            this.cbSelectTpye.SelectedIndex = -1;

            //清空当前文本框
            this.tbNodeID.Text = string.Empty;
            this.tbNodeIDName.Text = string.Empty;
            this.tbParentNodeID.Text = string.Empty;
            this.tbURL.Text = string.Empty;

            this.IsEnableTextBox(TabelType.TreeTabel, false);
        }

        #endregion 权限树设置

        #region 树相关

        #region 树结点 增删改的服务委托 实现
        /// <summary>
        /// 树结点 增删改的服务委托 实现
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AccountClinet_TreeViewNodeCompleted(object sender, TreeViewNodeCompletedEventArgs e)
        {
            int messageBoxInfor = 0;
            try
            {
                if (e.Error == null && e.Result.Length > 0)
                {
                    throw new Exception(e.Result.ToString());
                }
                else 
                {
                    messageBoxInfor = 1;
                    throw new Exception("操作有误！");
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + " AccountClinet_TreeViewNodeCompleted 树结点操作方法 " + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                                       this.errorMessbox,
                                       messageBoxInfor,
                                       "提示",
                                       e.Result.ToString(),
                                       Colors.Gray,
                                       true,
                                       Visibility.Visible,
                                       Visibility.Collapsed);
            }
        }
        #endregion 树结点 增删改的服务委托 实现

        #region  树形结构 的服务现实

        /// <summary>
        /// 显示树形结构 的服务现实
        /// </summary>
        /// <param name="sender">sender of object</param>
        /// <param name="e">e type of  TreeViewListCompletedEventArgs</param>
        private void ClientTreeView_TreeViewListCompleted(object sender, TreeViewListCompletedEventArgs e)
        {
            try
            {
                this.clientTreeInforList.Clear();
                if (e.Error == null & e.Result.Count > 0)
                {
                    // 将服务端树形结构存储在客户端
                    foreach (WCFServers.WCFAccountsRef.TreeViewDataList tvdl in e.Result)
                    {
                        this.clientTreeInforList.Add(new ClientTreeInfor()
                        {
                            NodeID = tvdl.NodeID.ToString().Trim(),
                            NodeName = tvdl.NodeName.ToString().Trim(),
                            NodeParendID = tvdl.NodeParendID.ToString().Trim(),
                            TagUri = tvdl.TagUri.ToString().Trim(),
                            System = tvdl.System.ToString().Trim()
                        });
                    }

                    // RoleID 为0，用户或为初始设置，或没有管理权
                    if (!ClientUserInfor.RoleID.Equals("0"))
                    {
                        // 形成树形结构
                        this.AddTreeNode("0", null);
                    }
                }
            }
            catch (Exception ex)
            {
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + " ClientTreeView_TreeViewListCompleted 形成树形结构方法 " + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        /// <summary>
        /// 形成树形结构
        /// AddTreeNode
        /// </summary>
        /// <param name="nodeParendID">前一级 结点名称 nodeParendID</param>
        /// <param name="treeViewItem">TreeViewItem treeViewItem</param>
        private void AddTreeNode(string nodeParendID, TreeViewItem treeViewItem)
        {
            List<ClientTreeInfor> result = new List<ClientTreeInfor>();
            // 根据NodeParendID来查找当前一级的结点。
            result = (from treeListInfo in clientTreeInforList
                                            where treeListInfo.NodeParendID == nodeParendID
                                            select treeListInfo).ToList<ClientTreeInfor>();

            #region 递归
            if (result.Count > 0)
            {
                foreach (ClientTreeInfor foruminfo in result)
                {
                    TreeViewItem objTreeNode = new TreeViewItem();
                    objTreeNode.Header = foruminfo.NodeName + " (" + foruminfo.NodeID + ")";
                    objTreeNode.DataContext = foruminfo;
                    objTreeNode.IsExpanded = true;

                    ////此样式将会添加的所有叶子结点上
                    ////objTreeNode.ItemContainerStyle = this.Resources["RedItemStyle"] as Style;

                    // 添加根节点
                    if (treeViewItem == null)
                    {
                        TreeOfList.Items.Add(objTreeNode);
                    }
                    else
                    {
                        treeViewItem.Items.Add(objTreeNode);
                    }

                    this.AddTreeNode(foruminfo.NodeID, objTreeNode);
                }
            }
            #endregion
        }
        #endregion  服务实现

        #region TreeView相关方法
        /// <summary>
        /// 新建一个树对象
        /// </summary>
        private void CreateNewTreeView()
        {
            this.TreeOfList = null;
            this.TreeOfList = new TreeView();
            this.TreeOfList.Background = null;
            this.TreeOfList.BorderBrush = new SolidColorBrush(Colors.LightGray);
            this.TreeOfList.FontSize = 12;
            this.TreeOfList.Foreground = new SolidColorBrush(Colors.Black);

            // 点击树形结点事件
            this.TreeOfList.SelectedItemChanged -= new RoutedPropertyChangedEventHandler<object>(TreeOfList_SelectedItemChanged);
            this.TreeOfList.SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(TreeOfList_SelectedItemChanged);
        }
        
        /// <summary>
        /// TreeView事件
        /// TreeOfList_SelectedItemChanged
        /// </summary>
        /// <param name="sender">sender of object</param>
        /// <param name="e">e type of RoutedPropertyChangedEventArgs</param>
        private void TreeOfList_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            try
            {
                this.IsEnableTextBox(TabelType.TreeTabel, false);
                this.cbSelectTpye.SelectedIndex = -1;

                TreeViewItem item = e.NewValue as TreeViewItem;
                ClientTreeInfor cti = item.DataContext as ClientTreeInfor;

                if (cti != null)
                {
                    this.tbParentNodeID.Text = cti.NodeParendID;
                    this.tbNodeID.Text = cti.NodeID;
                    this.tbNodeIDName.Text = cti.NodeName;
                    this.tbURL.Text = cti.TagUri;
                }
            }
            catch (Exception ex)
            {
                this.IsEnableTextBox(TabelType.TreeTabel, false);
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + " TreeOfList_SelectedItemChanged TreeView选择事件" + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion  TreeView相关方法

        #endregion 树相关

        #region  身份权限设置

        /// <summary>
        /// 身份权限设置
        /// 下拉框选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cbRolesSelectTpye_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.paramRolesClass = null;
            this.paramRolesClass = new WCFServers.WCFAccountsRef.RolesCombboxDataList();
            switch (this.cbRolesSelectTpye.SelectedIndex)
            {
                case 0:
                    //刷新 Update
                    this.IsEnableTextBox(TabelType.RolesTabel, false);
                    break;
                case 1:
                    //添加 Add

                    //清空当前文本框
                    this.tbRolesNodeID.Text = string.Empty;
                    this.tbRoleName.Text = string.Empty;
                    this.tbCondition.Text = string.Empty;

                    this.IsEnableTextBox(TabelType.RolesTabel, true);

                    break;
                case 2:
                    //编辑 Edit
                    this.IsEnableTextBox(TabelType.RolesTabel, true);

                    //记录要编辑的OldRoleName号
                    this.paramRolesClass.OldRoleName = this.tbRoleName.Text.Trim();

                    break;
                case 3:
                    //删除 Delete

                    break;
                default:
                    //不可操作的选择
                    break;
            }
        }

        /// <summary>
        /// 显示所有的用户身份
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">instance containing the event data.</param>
        void AccountClinet_AllRolesListCompleted(object sender, AllRolesListCompletedEventArgs e)
        {
            try
            {
                if (e.Error == null && e.Result.Count > 0)
                {
                    this.dgAllRolesList.ItemsSource = null;
                    this.dgAllRolesList.ItemsSource = e.Result;
                }
                else 
                {
                    this.dgAllRolesList.ItemsSource = null;
                    throw new Exception("没有可显示的数据！");
                }
            }
            catch (Exception ex)
            {
                this.IsEnableTextBox(TabelType.RolesTabel, false);
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + " AccountClinet_AllRolesListCompleted " + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                               this.errorMessbox,
                               1,
                               "提示",
                               ex.Message.ToString(),
                               Colors.Gray,
                               true,
                               Visibility.Visible,
                               Visibility.Collapsed);
                return;
            }
        }
        

        /// <summary>
        /// DATAGRID的记录单击事件
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void dgAllRolesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                this.IsEnableTextBox(TabelType.RolesTabel, false);
                this.cbRolesSelectTpye.SelectedIndex = -1;
                var selectData = e.AddedItems[0] as WCFServers.WCFAccountsRef.RolesCombboxDataList;

                if (selectData != null)
                {
                    this.tbRolesNodeID.Text = selectData.RoleID.ToString();
                    this.tbRoleName.Text = selectData.RoleName.ToString();
                    this.tbCondition.Text = selectData.Condition.ToString();
                }
                else 
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                //索引超界
                return;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The  instance containing the event data.</param>
        void btnRolesOK_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.IsEnableTextBox(TabelType.RolesTabel, false);

                switch (this.cbRolesSelectTpye.SelectedIndex)
                {
                        //刷新
                    case 0:
                        this.accountClinet.AllRolesListAsync();
                        break;

                    case 1:
                        //添加
                        //判断输入的TextBox是否有空值 
                        IsEmptyTextBox(this.setCheckRolesStackPanel);

                        this.paramRolesClass.RoleID = this.tbRolesNodeID.Text.Trim();
                        this.paramRolesClass.RoleName  = this.tbRoleName.Text.Trim();
                        this.paramRolesClass.Condition  = this.tbCondition.Text.Trim();
                        
                        break;
                    case 2:
                        //编辑当前节点
                        IsEmptyTextBox(this.setCheckRolesStackPanel);

                        this.paramRolesClass.RoleID = this.tbRolesNodeID.Text.Trim();
                        this.paramRolesClass.RoleName = this.tbRoleName.Text.Trim();
                        this.paramRolesClass.Condition = this.tbCondition.Text.Trim();
                        //要编辑的RoleName号已经记录

                        break;
                    case 3:
                        //删除当前节点
                        if (string.IsNullOrEmpty(this.tbRoleName.Text.Trim())) 
                        {
                            throw new Exception("选择要删除的内容！");
                        }
                        this.paramRolesClass.RoleName = this.tbRoleName.Text.Trim();
                        break;
                    default:
                        //不可操作的选择
                        this.paramRolesClass = null;
                        break;
                }

                if (this.paramRolesClass == null)
                {
                    throw new Exception("请选择一个操作!");
                }

                if (this.cbRolesSelectTpye.SelectedIndex != 0)
                {
                    //调用服务
                    this.accountClinet.EditRolesListAsync(this.paramRolesClass, (this.cbRolesSelectTpye.SelectedItem as ComboBoxItem).Tag.ToString());
                }
                this.cbRolesSelectTpye.SelectedIndex = -1;

            }
            catch (Exception ex)
            {
                this.cbRolesSelectTpye.SelectedIndex = -1;

                this.IsEnableTextBox(TabelType.RolesTabel, false);
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + " RolesOK_Click " + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   1,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The instance containing the event data.</param>
        void btnRolesCancel_Click(object sender, RoutedEventArgs e)
        {
            this.cbRolesSelectTpye.SelectedIndex = -1;
            //清空当前文本框
            this.tbRolesNodeID.Text = string.Empty;
            this.tbRoleName.Text = string.Empty;
            this.tbCondition.Text = string.Empty;

            this.IsEnableTextBox(TabelType.RolesTabel, false);
        }
        
        /// <summary>
        /// 身份权限设置 增删改的服务 实现
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The  instance containing the event data.</param>
        void accountClinet_EditRolesListCompleted(object sender, EditRolesListCompletedEventArgs e)
        {
            int messageBoxInfor = 0;
            try
            {
                this.IsEnableTextBox(TabelType.RolesTabel, false);

                if (e.Error == null && e.Result.Length >0)
                {
                    this.accountClinet.AllRolesListAsync();
                    throw new Exception(e.Result.ToString());
                }
                else
                {
                    messageBoxInfor = 1;
                    throw new Exception("操作有误！");
                }
            }
            catch (Exception ex)
            {
                this.IsEnableTextBox(TabelType.RolesTabel, false);
                this.wcfLogClient.ErrorAsync(((App)Application.Current).LogStr + pageName + " accountClinet_EditRolesListCompleted " + ex.Message.ToString());
                FunctionClass.ShowMessageBox(
                   this.errorMessbox,
                   messageBoxInfor,
                   "提示",
                   ex.Message.ToString(),
                   Colors.Gray,
                   true,
                   Visibility.Visible,
                   Visibility.Collapsed);
                return;
            }
        }

        #endregion  身份权限设置

        #region 设置文本框是否可用
        /// <summary>
        /// 设置文本框是否可用
        /// </summary>
        /// <param name="selTabType">tab标签区域名</param>
        /// <param name="setEnable">True:可用  False:不可用</param>
        private void IsEnableTextBox(TabelType selTabType, bool setEnable)
        {
            if (selTabType == TabelType.TreeTabel)
            {
                this.tbNodeID.IsEnabled = setEnable;
                this.tbNodeIDName.IsEnabled = setEnable;
                this.tbParentNodeID.IsEnabled = setEnable;
                this.tbURL.IsEnabled = setEnable;
            }
            if (selTabType == TabelType.RolesTabel)
            {
                this.tbRolesNodeID.IsEnabled = setEnable;
                this.tbRoleName.IsEnabled = setEnable;
                this.tbCondition.IsEnabled = setEnable;
            }
        }
        #endregion 设置文本框是否可用

        #region 判断指定的StackPanel里的TextBox是否为空值
        /// <summary>
        /// 判断指定的StackPanel里的TextBox是否为空值
        /// </summary>
        /// <param name="stackpanel">指定的StackPanel的名字</param>
        private void IsEmptyTextBox(StackPanel stackpanel)
        {
            foreach (UIElement uiObject in stackpanel.Children)
            {
                StackPanel uiStackPanel = uiObject as StackPanel;
                //如果是StackPanel
                if (uiStackPanel != null)
                {
                    foreach (UIElement uiTextBox in uiStackPanel.Children)
                    {
                        TextBox tb = uiTextBox as TextBox;
                        if (tb != null)
                        {
                            if (string.IsNullOrEmpty(tb.Text))
                            {
                                throw new Exception(tb.Tag + "值不能为空！");
                            }
                        }
                    }
                }
            }
        }
        #endregion 判断指定的STACKPANEL里的TEXTBOX是否为空值

    }
}
